Ext.define("App.project.view.ProjectRefReportEditorWindow", {
    extend: 'Extend.window.FormWindow',
    alias: 'widget.ProjectRefReportEditorWindow',
    entity: 'entity',
    requires: ['App.hrm.employee.field.EmployeeComboBox', 'App.project.field.ProjectTypeComboBox', 'App.project.field.IsBusinessProjectComboBox', 'App.project.field.BillingTypeComboBox',
        'App.project.field.ImplementationStatusComboBox'],
    resetBySave: false,
    listeners: {},
    config: {
        window: {
            height: 600,
            width: 1000
        }
    },
    defaults: {
        labelWidth: 110,
        columnWidth: 0.25
    },
    items: [{
        xtype: 'hidden',
        name: 'id'
    }, {
        xtype: 'textfield',
        fieldLabel: '项目名称',
        name: 'name',
        columnWidth: .5,
        maxLength: 128,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: 'PO号',
        name: 'projectOrder.po',
        columnWidth: .5,
        maxLength: 128,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: 'PO名称',
        name: 'projectOrder.name',
        columnWidth: .5,
        maxLength: 128,
        submitValue: false,
        readOnly: true
    }, {
        xtype: 'textfield',
        fieldLabel: '内部Po号',
        name: 'innerPoNumber',
        maxLength: 128,
        columnWidth: .5,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '所在DU',
        name: 'du',
        columnWidth: .5,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '所在交付部',
        name: 'dd',
        columnWidth: .5,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'ProjectTypeComboBox',
        fieldLabel: '项目类型',
        name: 'projectType',
        maxLength: 128,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '项目编码',
        name: 'projectCode',
        maxLength: 128,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'numberfield',
        fieldLabel: 'PO占比(%)',
        name: 'poProportion',
        maxLength: 128,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'IsBusinessProjectComboBox',
        fieldLabel: '是否为上网项目',
        name: 'business',
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'BillingTypeComboBox',
        fieldLabel: '计费类型',
        name: 'billingType',
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'numberfield',
        fieldLabel: '需求总人数',
        name: 'itemPlanMember',
        minValue: 1,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '华为QA',
        name: 'huaweiQa',
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '华为项目经理',
        name: 'huaweiProjectManager',
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'EmployeeComboBox',
        fieldLabel: '中软QA',
        name: 'chinasoftQa',
        extraParams: {
            'params.role_eq': 'QA'
        },
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '项目经理',
        name: 'projectManager',
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '项目经理工号',
        name: 'pmNo',
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'numberfield',
        fieldLabel: '预计工作量(人天)',
        name: 'projectWorkload',
        minValue: 0,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'datefield',
        fieldLabel: '项目开始时间',
        name: 'startDate',
        format: 'Y-m-d',
        editable: false,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'datefield',
        fieldLabel: '计划结项时间',
        name: 'plannedEndDate',
        format: 'Y-m-d',
        editable: false,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '所在地域',
        name: 'area',
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'textfield',
        fieldLabel: '描述',
        name: 'description',
        columnWidth: 1,
        readOnly: true,
        submitValue: false
    }, {
        xtype: 'tabpanel',
        columnWidth: 1,
        height: 280,
        items: [
            {
                xtype: 'ReportConfigurationReferencesGridField',
                name: 'projectReportConfigurationReferences',
                title: '项目报表',
                reportConfigurationType: 'Project'
            },
            {
                xtype: 'ReportConfigurationReferencesGridField',
                name: 'iterationReportConfigurationReferences',
                title: '迭代报表',
                reportConfigurationType: 'Iteration'
            }
        ]
    }]
});


Ext.define('ReportConfigurationReferencesGridField', {
    extend: 'Extend.form.field.GridField',
    alias: ['widget.ReportConfigurationReferencesGridField'],
    readOnly: false,
    reportConfigurationType: 'Iteration',
    submitFields: ['id', 'reportConfiguration.id', {column: 'index', field: 'idx'}],
    addHandler: function () {
        var grid = this;
        Ext.create('Extend.window.SelectionWindow', {
            height: 500,
            grid: 'App.reportconfiguration.view.ReportConfigurationSelection',
            getExtraParams: function () {
                var ids = [];
                grid.getStore().each(function (record) {
                    ids.push(record.get('reportConfiguration').id)
                });
                var params = {
                    'params.type_eq': grid.reportConfigurationType,
                    'params.id_notin': ids
                };
                return params;
            },
            listeners: {
                selected: function (rs) {
                    Ext.Array.each(rs, function (item) {
                        var r = Ext.create('Ext.data.Model', {reportConfiguration: item.data});
                        grid.loadRecords(r, true);
                    })
                }
            }
        }).show();
    },
    columns: [{
        header: '名称',
        dataIndex: 'name',
        renderer: function (v, m, r) {
            var value = r.get('reportConfiguration').name;
            return value;
        }
    }, {
        header: '描述',
        dataIndex: 'description',
        renderer: function (v, m, r) {
            var value = r.get('reportConfiguration').description;
            return value;
        }
    }, {
        header: '创建人',
        dataIndex: 'creator',
        renderer: function (v, m, r) {
            var value = r.get('reportConfiguration').creator;
            return value;
        }
    }, {
        xtype: 'ymdcolumn',
        header: '创建时间',
        dataIndex: 'cdt',
        renderer: function (v, m, r) {
            var value = r.get('reportConfiguration').cdt;
            return Ext.util.Format.date(new Date(value),'Y-m-d');
        }
    }]
});
